direction: down

# Start point
start: Start {
  shape: circle
}

# Main process boxes
check_accessibility: Use Accessibility API {
  shape: rectangle
}

check_frame: Check Text Frame {
  shape: diamond
}

text_found: Text Found? {
  shape: diamond
}

first_time: First Time Use? {
  shape: diamond
}

request_permission: Request Accessibility Permission {
  shape: rectangle
}

check_browser: Is Browser? {
  shape: diamond
}

use_applescript: Use AppleScript {
  shape: rectangle
}

force_get_text: Force Get Text {
  shape: rectangle
}

check_force_type: Force Type? {
  shape: diamond
}

menu_bar_copy: Menu Bar Action Copy {
  shape: rectangle
}

simulated_key: Simulated Key Copy {
  shape: rectangle
}

end_success: Return Text {
  shape: circle
}

end_fail: Return nil {
  shape: circle
}

# Connections
start -> check_accessibility

check_accessibility -> check_frame
check_frame -> text_found: valid frame
check_frame -> end_fail: invalid frame

text_found -> end_success: yes
text_found -> first_time: no

first_time -> request_permission: yes
first_time -> check_browser: no

request_permission -> end_fail

check_browser -> use_applescript: yes
check_browser -> force_get_text: no

use_applescript -> end_success: success
use_applescript -> force_get_text: fail

force_get_text -> check_force_type
check_force_type -> menu_bar_copy: "MenuBarActionCopy"
check_force_type -> simulated_key: "SimulatedKey"

menu_bar_copy -> end_success: success
menu_bar_copy -> end_fail: fail

simulated_key -> end_success: success
simulated_key -> end_fail: fail

# Styles
style {
  fill: "#f5f5f5"
  stroke: "#333"
  stroke-width: 2
  font-size: 14
}

end_success.style: {
  fill: "#90EE90"
  stroke: "#006400"
}

end_fail.style: {
  fill: "#FFB6C1"
  stroke: "#8B0000"
}

force_get_text.style: {
  fill: "#FFE4B5"
  stroke: "#DAA520"
}
